package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-07-04
 * Time: 17:25
 */
public class Test {
    public static int countSegments(String s){
        if(s == null){
            return 0;
        }

        if(s.isEmpty()){
            return 0;
        }
        int count = 0;
        String[] ret = s.split(" ");
        for (String x:ret) {
            if(x.length() != 0){
                count++;
            }
        }
        return count;
    }
    public static void main(String[] args) {
        String str = "abc cbd def fhi";
        int ret = countSegments(str);
        System.out.println(ret);
    }
}
